var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic');
var common = require('../../../utils/common')
Page({
  data: {
    selectPerson: true,
    selectArea: false,

    nickName: "",
    avatarUrl: "",
    casArray: ['请选择您的问题类型', '新需求建议', '功能问题反馈', '其他问题'],
    userName: '',
    mobile: '',
    Gender: 'female',
    casIndex: 0,

    orgid: "",
    userid: "",
    idea: "",
    phone: "",
  }, idea: function (e) {
    this.setData({
      idea: e.detail.value
    })
  }, phone: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  send: function () {
    let xz = this.data.casIndex - 1;
    if (xz == -1) {
      common.showToast("请选择", "none");
    } else
      if (this.data.idea.replace(/(^\s*)|(\s*$)/g, "") == "" || this.data.phone.replace(/(^\s*)|(\s*$)/g, "") == "") {
        common.showToast("内容不能为空", "none");
      } else if (this.data.phone.length < 4 || this.data.phone.length > 40) {
        common.showToast("标题必须4-40字", "none");
      } else if (this.data.idea.length < 15 || this.data.idea.length > 500) {
        common.showToast("内容必须15-400字", "none");
      } else {
      let InfoJson = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid": "735a3393-c402-4a3d-b57a-a34b93b4b02e","type":"' + xz + '","content":"' + this.data.idea + '","peopleid":"' + this.data.userid + '","contactinformation":"' + this.data.phone + '"}';

      let params = { "orgid": this.data.orgid, "userid": this.data.userid, InfoJson: InfoJson };
      businessLogic.SubmitFeedback(params, (res) => {
        if (res == "成功") {
          common.showToast(res, "none");
          wx.redirectTo({
            url: "../set/set",
            
          })
        } else {
          common.showToast(res, "none");
        }


      });
    }


  },
  //点击选择类型
  clickPerson: function () {
    var selectPerson = this.data.selectPerson;
    if (selectPerson == true) {
      this.setData({
        selectArea: true,
        selectPerson: false,
      })
    } else {
      this.setData({
        selectArea: false,
        selectPerson: true,
      })
    }
  },
  //点击切换
  mySelect: function (e) {
    this.setData({
      firstPerson: e.target.dataset.me,
      selectPerson: true,
      selectArea: false,
    })
  }, bindCasPickerChange: function (e) {

    // console.log(this.data.casArray[e.detail.value])

    if (e.detail.value == 4) {
      this.setData({ reply: true })
    } else {
      this.setData({ reply: false })
    }
    this.setData({
      casIndex: e.detail.value
    })

  },
  onLoad: function (options) {
    var orgid = common.getStorageSync("orgid")
    var userid = common.getStorageSync("userid")
    this.setData({
      orgid: orgid,
      userid: userid,
    });
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
})